<template>
    <el-dialog
            :title="!dataForm.orderId ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="唯一标识" prop="id">
                        <el-input v-model.number="dataForm.id" placeholder="唯一标识"></el-input>
                </el-form-item>
                <el-form-item label="数据标识" prop="dataId">
                        <el-input v-model.number="dataForm.dataId" placeholder="数据标识"></el-input>
                </el-form-item>
                <el-form-item label="特征名称" prop="featureName">
                        <el-input v-model="dataForm.featureName" placeholder="特征名称"></el-input>
                </el-form-item>
                <el-form-item label="原始特征值" prop="originalFeatureValue">
                        <el-input v-model="dataForm.originalFeatureValue" placeholder="原始特征值"></el-input>
                </el-form-item>
                <el-form-item label="处理后的特征值" prop="engineeredFeatureValue">
                        <el-input v-model="dataForm.engineeredFeatureValue" placeholder="处理后的特征值"></el-input>
                </el-form-item>
                <el-form-item label="归一化或标准化方法" prop="normalizationMethod">
                        <el-input v-model="dataForm.normalizationMethod" placeholder="归一化或标准化方法"></el-input>
                </el-form-item>
                <el-form-item label="特征组合（如果有）" prop="featureCombination">
                        <el-input v-model="dataForm.featureCombination" placeholder="特征组合（如果有）"></el-input>
                </el-form-item>
                <el-form-item label="创建时间" prop="createdAt">
                        <el-date-picker
                                v-model="dataForm.createdAt"
                                type="datetime"
                                placeholder="创建时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="更新时间" prop="updatedAt">
                        <el-date-picker
                                v-model="dataForm.updatedAt"
                                type="datetime"
                                placeholder="更新时间">
                        </el-date-picker>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
        data () {
            return {
                visible: false,
                dataForm: {
                    id: null,
                    dataId: null,
                    featureName: null,
                    originalFeatureValue: null,
                    engineeredFeatureValue: null,
                    normalizationMethod: null,
                    featureCombination: null,
                    createdAt: null,
                    updatedAt: null,
                },
                dataRule: {
                    id: [
                        { required: true, message: '唯一标识不能为空', trigger: 'blur' }
                    ],
                    dataId: [
                        { required: true, message: '数据标识不能为空', trigger: 'blur' }
                    ],
                    featureName: [
                        { required: true, message: '特征名称不能为空', trigger: 'blur' }
                    ],
                    originalFeatureValue: [
                        { required: true, message: '原始特征值不能为空', trigger: 'blur' }
                    ],
                    engineeredFeatureValue: [
                        { required: true, message: '处理后的特征值不能为空', trigger: 'blur' }
                    ],
                    normalizationMethod: [
                        { required: true, message: '归一化或标准化方法不能为空', trigger: 'blur' }
                    ],
                    featureCombination: [
                        { required: true, message: '特征组合（如果有）不能为空', trigger: 'blur' }
                    ],
                    createdAt: [
                        { required: true, message: '创建时间不能为空', trigger: 'blur' }
                    ],
                    updatedAt: [
                        { required: true, message: '更新时间不能为空', trigger: 'blur' }
                    ],
                }
            }
        },
        methods: {
            init (id) {
                this.dataForm.orderId = id || 0
                this.visible = true
                this.$nextTick(() => {
                    this.$refs['dataForm'].resetFields()
                    this.dataForm.orderId = id || 0
                    if (this.dataForm.orderId) {
                        this.$http({
                            url: this.$http.adornUrl(`/app/AppFeatureEngineering/info/\\$\\{this.dataForm.orderId}`),
                            method: 'get',
                            params: this.$http.adornParams()
                        }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.dataForm = data.appfeatureengineering
                            }
                        })
                    }
                })
            },
            // 表单提交
            dataFormSubmit () {
                this.$refs['dataForm'].validate((valid) => {
                    if (valid) {
                        this.$http({
                            url: this.$http.adornUrl(`/app/AppFeatureEngineering/\\$\\{!this.dataForm.orderId ? 'save' : 'update'}`),
                            method: 'post',
                            data: this.$http.adornData(this.dataForm)
                        }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.$message({
                                    message: '操作成功',
                                    type: 'success',
                                    duration: 1500,
                                    onClose: () => {
                                        this.visible = false
                                        this.$emit('refreshDataList')
                                    }
                                })
                            } else {
                                this.$message.error(data.msg)
                            }
                        })
                    }
                })
            }
        }
    }
</script>